package cn.vihub.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author: 秋晚
 * @Date: 2025/7/18 14:03
 * @Description:
 **/
@Data
public class Result<T> implements Serializable {

    //定义数据
    //自定义状态码
    private Integer code = 200;

    //说明
    private String msg = "success";

    //数据
    private T data;

    //构造器

    //如果是空的  就传默认值
    public Result() {
    }

    //自定义属性内容
    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //自定义状态码和说明
    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    //自定义数据
    public Result(T data) {
        this.data = data;
    }




    //静态方法
    public static <T> Result<T> success(){
        return new Result<>();
    }

    public static <T> Result<T> success(T data){
        return new Result<>(data);
    }

    public static <T> Result<T> error(){
        return new Result<>(-1,"error");
    }

    public static <T> Result<T> error(Integer code){
        return new Result<>(code,"error");
    }

    public static <T> Result<T> error(Integer code,String msg){
        return new Result<>(code,msg);
    }

    public static <T> Result<T> error(String msg){
        return new Result<>(-1,msg);
    }

}
